<?php
namespace app\api\controller\v1;
use app\api\controller\Common;

class Label extends Common{
	var $modelDb;
	public function _initialize(){
		parent::_initialize();
		$this->modelDb = model("Label");
	}

	public function add(){
		$this->postData['userid'] = $this->uinfo['id'];
		$results = $this->validate($this->postData, 'Label.check_number');
        if ($results !== true) {
			return $this->app_error($results);
		}
        $result = $this->validate($this->postData, 'Label.check_label');
        if ($result !== true) {
			return $this->app_error($result);
		}
	    $id = $this->modelDb->save_data($this->postData);
		if($id === false){
            return $this->app_error($this->modelDb->getError());
        }         
        $id = $this->modelDb->save_label($this->postData);         
        return $this->app_success();
    }

    public function delete_label(){
    	$this->postData['userid'] = $this->uinfo['id'];
        $id = $this->modelDb->where('userid', $this->uinfo['id'])->where('label',$this->postData['label'])->delete();
        if($id === false){
            return $this->app_error($this->modelDb->getError());
        } 
        $id = $this->modelDb->save_label($this->postData);         
        return $this->app_success();
        
    }



}